<?php

namespace App\Models\Diary;

use App\Libs\Base\Constant;
use Phalcon\Mvc\Model\Query\Builder;
class Diary extends \App\Libs\Base\BaseModel
{
    protected $numPerPage = 10;
    protected $__TABLE__ = 't_paile_diary';

    /**
     *    跳过检测了
     */
    public function beforeValidation()
    {
        self::skipValidation(['type','diary_num'], $this);
    }

    public function getResult()
    {
//       $builder =  $this->modelsManager->createBuilder();
//       return $resutl = $builder->from('Diary')->getQuery();
        $builder = Builder::createSelectBuilder();
        return $builder->from('Diary')->getQuery()->execute();
    }


    public static function addReadNum($diaryId)
    {
        $diary = self::find([
            'conditions' => 'id=?1',
            'bind' => [1 => $diaryId]
        ]);
        $diary->read_num += 1;
        $diary->update();

    }


}
